﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MiniCrawler
{
    class FormatDateTimeHandler
    {
        #region DateTime

        /// <summary>
        /// Convert dd/MM/yyyy hh:mm to DateTime
        /// </summary>
        /// <param name="dd_MM_yyyy_hh_mm"></param>
        /// <returns></returns>
        public static DateTime ConvertDD_MM_YYYY_HH_MMToDateTime(string dd_MM_yyyy_hh_mm)
        {
            string[] listNgayGio = dd_MM_yyyy_hh_mm.Split(' ');
            string[] listNgay = listNgayGio[0].Split('/');
            string[] listGio = listNgayGio[1].Split(':');
            int ngay = Convert.ToInt32(listNgay[0]);
            int thang = Convert.ToInt32(listNgay[1]);
            int nam = Convert.ToInt32(listNgay[2]);
            int gio = Convert.ToInt32(listGio[0]);
            int phut = Convert.ToInt32(listGio[1]);
            return CreateDateTime(nam, thang, ngay, gio, phut, 00, 00);
        }

        /// <summary>
        /// Convert dd/MM/yyyy to DateTime + gio phut giay
        /// </summary>
        /// <param name="dd_MM_yyyy"></param>
        /// <param name="gio"></param>
        /// <param name="phut"></param>
        /// <param name="giay"></param>
        /// <returns></returns>
        public static DateTime ConvertDD_MM_YYYYToDateTime(string dd_MM_yyyy, int gio, int phut, int giay)
        {
            string[] listNgayGio = dd_MM_yyyy.Split(' ');
            string[] listNgay = listNgayGio[0].Split('/');
            int ngay = Convert.ToInt32(listNgay[0]);
            int thang = Convert.ToInt32(listNgay[1]);
            int nam = Convert.ToInt32(listNgay[2]);
            return CreateDateTime(nam, thang, ngay, gio, phut, giay, 00);
        }

        /// <summary>
        /// Function: Create DateTime
        /// </summary>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <param name="date"></param>
        /// <param name="hour"></param>
        /// <param name="minute"></param>
        /// <param name="second"></param>
        /// <param name="milisecond"></param>
        /// <returns></returns>
        public static DateTime CreateDateTime(int year, int month, int date, int hour, int minute, int second,
                                              int milisecond)
        {
            return new DateTime(year, month, date, hour, minute, second, milisecond);
        }

        #endregion

      
    }
}
